package cn.dapeng.common;

import org.apache.commons.lang3.StringUtils;

/**
 * @BelongProject study
 * @BelongPackage cn.dapeng.common
 * @Description TODO
 * @ClassName StringTools
 * @Author xupenghong
 * @Date 2024/8/23 15:06
 * @Version 1.0.0
 */
public class StringTools extends StringUtils {

    public static String getValues(String str, String beginChar, String endChar, String... replacements) {
        int startIndex, replaceIndex = 0;
        while ((startIndex = str.indexOf(beginChar)) > -1) {
            String target = str.substring(startIndex, str.indexOf(endChar) + 1);
            str = str.replace(target, replacements[replaceIndex++]);
        }
        return str;
    }

    /**
     * 传入 ["fl","sc"]
     *
     * @param str
     * @return
     */
    public static String[] toArray(String str, String startChar, String endChar, String splitChar) {
        return substringBetween(str, startChar, endChar).split(splitChar);
    }

    public static void main(String[] args) {
        System.out.println(getValues("欢迎{Hello World}莅临指导 {gun}", "{", "}", "ultra", "power"));

        String str = " a b c ";
        System.out.println(str.trim());
        System.out.println(str.strip());
    }
}
